package com.ytkj.digitalConstruction.socketio;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.druid.util.StringUtils;
import com.corundumstudio.socketio.SocketIOClient;
import com.corundumstudio.socketio.SocketIOServer;
import com.corundumstudio.socketio.listener.DisconnectListener;
import com.ytkj.digitalConstruction.redis.RedisHashService;
import com.ytkj.digitalConstruction.util.SpringUtil;

public class DisConnectListener implements DisconnectListener{
	Logger logger = LoggerFactory.getLogger(getClass());
	@SuppressWarnings("unchecked")
	private RedisHashService<ClientInfo> redisHashClientInfoService = SpringUtil.getBean(RedisHashService.class);
	SocketIOServer server;
	
	public void setServer(SocketIOServer server) {
		this.server = server;
	}

	@Override
	public void onDisconnect(SocketIOClient client) {
		logger.info("disconn ...");
		String clientId = client.getHandshakeData().getSingleUrlParam("clientId");
		if(StringUtils.isEmpty(clientId)) {
			return;
		}
		logger.info("clientId:"+clientId);
		//移除当前客户端
		redisHashClientInfoService.remove("client",clientId);
	}

}
